package com.yq.netty.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @ClassName NIOFileChannel02
 * @Description 本地文件读
 * @Author yaoqiang
 * @Date 2021/3/24 9:58
 * @Version 1.0
 */
public class NIOFileChannel02 {
    public static void main(String[] args) throws IOException {
        //创建文件输入流
        File file = new File("D://a.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        //通过输入流获取对应的channel
        FileChannel channel = fileInputStream.getChannel();
        //创建缓冲区
        ByteBuffer byteBuffer = ByteBuffer.allocate((int) file.length());
        int read = channel.read(byteBuffer);
        //奖字节信息转成字符串
        System.out.println(new String(byteBuffer.array()));
        fileInputStream.close();


    }
}
